package bookez.view.bean.backing;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import bookez.view.bean.NavigationResults;
import bookez.view.bean.UserBean;

@ManagedBean
@ViewScoped
public class AdminProfile extends BaseBackingBean {
	
	
	public String logout() {
		this.clear();
		return NavigationResults.LOGOUT_SUCCESS;
	}//end method logout
	
	public String changePassword() {
		return NavigationResults.NONE;
	}//end method changePassword
	
	/**
	 * Properties UserBean
	 * @return
	 */
	protected UserBean getUserBean() { return this.userBean; }
	public void setUserBean( UserBean value ) { this.userBean = value; }
	
	/**
	 * This is the name of user displayed on adminProfile
	 * @return
	 */
	public String getDisplayName() { 
		String username = getUserBean().getUsername().toLowerCase();
		StringBuilder builder = new StringBuilder( username );
		String firstChar = username.substring(0, 1);
		builder.replace( 0, 1, firstChar.toUpperCase() );
		return builder.toString();	  
	}//end method getDisplayName
	
	
	private void clear() {
		getUserBean().setAuthenticated( false );
		getUserBean().setUsername( null );
		getUserBean().setPassword( null );
	}//end method clear	
	
	@ManagedProperty ( value = "#{userBean}" )
	private UserBean userBean;
	
	private static final long serialVersionUID = -5948751749302034230L;

}//end class AdminProfile
